/*******************************************************************************
 * Copyright (c) 2012 Till Kolditz.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 * 
 * created on 10.10.2012 at 12:41:42
 * 
 *  Contributors:
 *      Till Kolditz
 *******************************************************************************/
package de.cc.yFilesParser.action;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

import de.cc.yFilesParser.Activator;
import de.cc.yFilesParser.wizard.ConvertWizard;
import de.kolditz.common.rcp.wizard.ExtendedWizardDialog;

/**
 * @author Till Kolditz - Till.Kolditz@GoogleMail.com
 */
public class ConvertAction implements IWorkbenchWindowActionDelegate, IHandler
{
    private ListenerList handlerListeners;

    /**
     * 
     */
    public ConvertAction()
    {
        handlerListeners = new ListenerList();
    }

    @Override
    public void run(IAction action)
    {
        ConvertWizard wizard = new ConvertWizard();
        ExtendedWizardDialog dialog = new ExtendedWizardDialog(Display.getDefault().getActiveShell(), wizard);
        dialog.setDialogBoundsSettings(Activator.getDefault().getDialogSettings());
        dialog.open();
    }

    @Override
    public void selectionChanged(IAction action, ISelection selection)
    {
    }

    @Override
    public void dispose()
    {
    }

    @Override
    public void init(IWorkbenchWindow window)
    {
    }

    @Override
    public void addHandlerListener(IHandlerListener handlerListener)
    {
        handlerListeners.add(handlerListener);
    }

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException
    {
        run(null);
        return null;
    }

    @Override
    public boolean isEnabled()
    {
        return true;
    }

    @Override
    public boolean isHandled()
    {
        return true;
    }

    @Override
    public void removeHandlerListener(IHandlerListener handlerListener)
    {
        handlerListeners.remove(handlerListener);
    }
}
